package Lee_code;

import java.util.*;
public class Lee_150 {

    public static int evalRPN(String[] tokens)
    {
        int re;
        Stack<Integer> stack = new Stack<>();
        int sum=0;
        for(String str: tokens)
        {
            if(str.equals("+"))
            {
                sum = stack.pop()+stack.pop();
                stack.push(sum);
            }
            else if(str.equals("-"))
            {
                sum = (-1)*(stack.pop()-stack.pop());
                stack.push(sum);
            }
            else if(str.equals("*"))
            {
                sum = stack.pop()* stack.pop();
                stack.push(sum);
            }
            else if(str.equals("/"))
            {
                int temp = stack.pop();
                sum = stack.pop()/temp;
                stack.push(sum);
            }
            else
            {
                int num = Integer.parseInt(str);
                stack.push(num);
            }
        }
        return stack.pop();
    }
    public static void main(String[] args) {

    }
}
